package cn.fl.institution.controller;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.constant.tripartite.InterfaceConstants;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.dto.MessageDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.service.ICstCorpBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.institution.constant.InsUtilConstant;
import cn.fl.institution.request.AssetManagerChangeCardParams;
import cn.fl.institution.vo.BankInfo;
import cn.fl.project.api.IPrjCstAccInfoApiService;
import cn.fl.project.condition.AssetManagerChangeCardCondition;
import cn.fl.project.condition.PrjCstAccInfoQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjCstAccInfoConstant;
import cn.fl.project.dto.PrjCstAccInfoDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstAccInfoService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.transform.PrjCstAccInfoVOTransform;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstAccInfoVO;
import cn.fl.system.api.ISysInsIvkValApiService;
import cn.fl.system.dto.SysInsIvkValDTO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.SysInsInterfaceConstant;
import fl.inf.facade.api.ITransLogApi;
import fl.inf.facade.condition.InfTransLogQueryCondition;
import fl.inf.facade.dto.InfTransLogDTO;
import fl.sn.facade.api.ISnApi;
import fl.sn.facade.dto.CustomerBankInfoDTO;
import fl.zbbank.facade.api.IZbBankApi;
import fl.zbbank.facade.dto.CstAccDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;

/**
 * @Description: 项目基础信息表 控制层 苏宁银行
 */
@Controller
@RequestMapping("/institution/snbank")
public class PrjBscInfoInsSNController {

	private static final Logger logger = LoggerFactory.getLogger(PrjBscInfoInsSNController.class);

    @Autowired
    private IPrjBscInfoService prjBscInfoService; // 项目基础信息表

	@Autowired
	private ISysInsIvkValApiService sysInsIvkValApiService; // 资管机构承接调用结果

	@Autowired
	private IPrjCstAccInfoApiService prjCstAccInfoApiService; // 项目客户账户信息表
	@Autowired
	private IPrjCstAccInfoService prjCstAccInfoService; // 项目客户账户信息表

	@Autowired
	private ICstBscInfoService cstBscInfoService; // 客户基础信息
	@Autowired
	private IProjectApiService projectApiService;
	@Autowired
	private ITransLogApi transLogApi;//日志表
	@Autowired
	private IZbBankApi zbBankApi;
	/**
	 * 代码映射服务
	 */
	@Autowired
	private ISysCdMapApiService sysCdMapApiService;
	@Autowired
	private ISnApi snApi;
	//法人客户基础信息表
	@Autowired
	private ICstCorpBscInfoService cstCorpBscInfoService;

	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	/**
	 * 保存 项目客户信息。
	 */
	@RequestMapping(value = "/save.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object save(Long prjId, HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "保存成功!");
		BaseLogUtils.info(logger, "save", "项目苏宁信息保存 ： ");
//
		try {
			PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
			BaseLogUtils.info(logger, "save", "项目苏宁信息保存 ： prjBscInfoVO = " + JSONObject.toJSONString(prjBscInfoVO));

			PrjCstAccInfoVO prjCstAccInfoVO = prjBscInfoVO.getPrjCstAccInfoVO();
			BaseLogUtils.info(logger, "save", "项目苏宁信息保存 ： prjCstAccInfoVO = " + JSONObject.toJSONString(prjCstAccInfoVO));

			// 查找开户接口的调用结果
			SysInsIvkValDTO sysInsIvkValDTO = sysInsIvkValApiService.getSysInsIvkValDTO(prjBscInfoVO.getId(), prjBscInfoVO.getFundRasInsId(),
					SysInsInterfaceConstant.InsTypeIntfConstant.SNBANK_TYPE_SIGN_ACCOUNT);
			BaseLogUtils.info(logger, "save", "项目苏宁信息保存 ： sysInsIvkValDTO = " + JSONObject.toJSONString(sysInsIvkValDTO));

			// 如果 开户接口的调用信息 不存在或者是失败，那么项目客户信息可以进行修改
			if(sysInsIvkValDTO == null || !sysInsIvkValDTO.isSuccess()) {
				PrjCstAccInfoQueryCondition prjCstAccInfoQC = this.getRequestParamForPrjCstAccInfo(request, prjCstAccInfoVO);
				BaseLogUtils.info(logger, "save", "项目苏宁信息保存 ： " + JSONObject.toJSONString(prjCstAccInfoQC));

				// 保存项目客户信息，包含四要素验证
                prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
				DataResultDTO resultDTO = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
				BaseLogUtils.info(logger, "save", "项目苏宁信息保存.resultDTO ： " + JSONObject.toJSONString(resultDTO));

				String chkRstCd = null, rstDesc = null;
				if(resultDTO != null && StringUtils.isNotEmpty(resultDTO.getCode())
						&& Integer.valueOf(resultDTO.getCode()) != BaseConstant.IS_YESNO_YES) {
					chkRstCd = resultDTO.getCode();
					rstDesc = resultDTO.getInfo();
				}
				else if(resultDTO != null && resultDTO.getData() != null) {
					@SuppressWarnings("unchecked")
					Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
					chkRstCd = ckResMap.get("chkRstCd");
					rstDesc = ckResMap.get("rstDesc");
				}

				if(chkRstCd == null || Integer.valueOf(chkRstCd) != BaseConstant.IS_YESNO_YES) {
					if(StringUtils.isNotEmpty(rstDesc)) {
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo(rstDesc);
					}
					else {
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo(resultDTO.getInfo());
					}
				}
			}
		}
		catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "save", "项目苏宁信息保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("保存失败!");
			BaseLogUtils.error(logger, "save", "项目苏宁信息保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}

		return result;
	}

	private PrjCstAccInfoQueryCondition getRequestParamForPrjCstAccInfo(HttpServletRequest request, PrjCstAccInfoVO prjCstAccInfoVO) throws BaseException {
		PrjCstAccInfoQueryCondition prjCstAccInfoQC = new PrjCstAccInfoQueryCondition();

		//获取参数
		Long id = prjCstAccInfoVO == null ? null : prjCstAccInfoVO.getId();
		String prjId = request.getParameter("prjId"); // 项目ID
		String cstId = request.getParameter("cstId"); // 客户ID
		String cstNm = request.getParameter("cstNm");//客户名称
		String mp = request.getParameter("mp");//客户手机号
//		String certNo = request.getParameter("certNo");//证件号码
		String accNo = request.getParameter("accNo");//银行账号
		String certTypCd = DictionaryConstant.CODE_CERT_TYP_CD_0;//证件类型（CST0005）
		String bkNm = request.getParameter("bkNm");//开户银行名称
		String bkNo = request.getParameter("bkNo");//开户行号
//		String chkRstCd = request.getParameter("chkRstCd");//校验结果 1.校验通过 2.校验不通过3.校验失败
		String fundRasInsId = request.getParameter("fundRasInsId");

		// 身份证号码
		String certNo = null;
		CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectDetailById(Long.valueOf(cstId));
		if (DictionaryConstant.CODE_CERT_TYP_CD_0.equals(cstBscInfoVO.getCertTypCd())) {
			certNo = cstBscInfoVO.getCertNo(); // 证件号码
		}

		prjCstAccInfoQC.setCertNo(certNo);
		prjCstAccInfoQC.setPrjId(Long.valueOf(prjId));
		prjCstAccInfoQC.setCstId(Long.valueOf(cstId));
		prjCstAccInfoQC.setCstNm(cstNm);//客户名称
		prjCstAccInfoQC.setMp(mp);//客户手机号
		prjCstAccInfoQC.setAccNo(accNo);//银行账号
		prjCstAccInfoQC.setCertTypCd(certTypCd);//证件类型（CST0005）
		prjCstAccInfoQC.setBkNm(bkNm);//开户银行名称
		prjCstAccInfoQC.setBkNo(bkNo);//开户行号
		prjCstAccInfoQC.setAccNm(cstNm);
		prjCstAccInfoQC.setBkCd(bkNo);
		if(fundRasInsId != null) {
			prjCstAccInfoQC.setInsId(Long.valueOf(fundRasInsId));
		}

		if (id != null) {
			prjCstAccInfoQC.setId(id);
		}

		return prjCstAccInfoQC;
	}
	/*
	 * 到列表页面
	 */
	@RequestMapping(value = "/toPrjBscInfoInsSNView.do", method = {RequestMethod.GET})
	public ModelAndView toLoanLaterPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toListPage", "加载到资管苏宁开户信息页面.", CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("institution/snbank/prjBscInfoInsSNList");

		// 获取有换卡需求的资管机构列表
		// List<KeyValueVO> insIdList = this.prjCstAccInfoService.getInsIdListOfChangeCard();
		List<SysDictionaryDTO> insCdList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), InsUtilConstant.SYS_DIS_CODE_INS_CARD_CHANGE);

		// 资管机构id
		view.addObject("insCdList", insCdList);
		return view;
	}

	/**
	 * 资管换卡信息列表
	 * @return
	 */
	@RequestMapping(value = "/searchAssetManagerChangeCard.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object searchAssetManagerChangeCard(@Valid AssetManagerChangeCardParams params, BindingResult result){
        // 字段值校验失败时返回错误信息
        if (result.hasErrors()){
            List<ObjectError> errorList = result.getAllErrors();
            return new DataResultVO(BaseConstant.IS_YESNO_NO, errorList.get(0).getDefaultMessage());
        }
        Pager page = new Pager();
        page.setCurrentPage(params.getPage());
        page.setEveryPage(params.getPagesize());

        AssetManagerChangeCardCondition qc = new AssetManagerChangeCardCondition();
        if(StringUtils.isNotEmpty(params.getCstNm())){
            qc.setCstNm(params.getCstNm());
        }
        if(StringUtils.isNotEmpty(params.getCertNo())){
            qc.setCertNo(params.getCertNo());
        }
        qc.setUsrId(CurrentThreadContext.getCurrentUserId());
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());

        if (StringUtils.isNotEmpty(params.getInsCode())) {
            qc.setInsCode(params.getInsCode());
        }else{
			List<SysDictionaryDTO> insCdList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), InsUtilConstant.SYS_DIS_CODE_INS_CARD_CHANGE);
            List<String> insCodeList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : insCdList) {
				if("snbanks".equals(sysDictionaryDTO.getCode()) || "snbank".equals(sysDictionaryDTO.getCode())){
                    insCodeList.add(sysDictionaryDTO.getCode());
				}
			}
			qc.setInsCodeList(insCodeList);
		}

        page.setCondition(qc);

        Pager pager  = this.prjCstAccInfoService.searchAssetManagerChangeCard(page);
        List<PrjCstAccInfoDTO> list = (List<PrjCstAccInfoDTO>) pager.getResultList();
        List<PrjCstAccInfoVO> voList = PrjCstAccInfoVOTransform.toVOList(list);
        ListPageVO<PrjCstAccInfoVO> listPage = new ListPageVO<PrjCstAccInfoVO>(voList,pager.getTotalCount());
        return listPage;
	}
	/*
	 * 资管苏宁开户信息列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/toPrjBscInfoInsSNList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object initList(HttpServletRequest request,HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String cstNm = request.getParameter("cstNm");//客户姓名
		String certNo = request.getParameter("certNo");//身份证号
		String signStatus = null; //签约状态

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		PrjCstAccInfoQueryCondition qc = new PrjCstAccInfoQueryCondition();
		if(StringUtils.isNotEmpty(cstNm)){
			qc.setCstNm(cstNm);
		}
		if(StringUtils.isNotEmpty(certNo)){
			qc.setCertNo(certNo);
		}
		qc.setUsrId(CurrentThreadContext.getCurrentUserId());
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());

		// 资管机构id
		String insId = request.getParameter("insId");
		if (StringUtils.isNotBlank(insId)) {
			qc.setInsId(Long.valueOf(insId));
		}

		page.setCondition(qc);
		Pager pager  = this.prjCstAccInfoService.searchPrjCstAccInfoPage(page);
		List<PrjCstAccInfoDTO> list = (List<PrjCstAccInfoDTO>) pager.getResultList();
		List<PrjCstAccInfoVO> voList = PrjCstAccInfoVOTransform.toVOList(list);
		ListPageVO<PrjCstAccInfoVO> listPage = new ListPageVO<PrjCstAccInfoVO>(voList,pager.getTotalCount());
		return listPage;
	}
	//苏宁还款卡-查看
	@RequestMapping(value = "/checkSNPrjBscInfo.do", method = { RequestMethod.GET })
	public ModelAndView checkSNPrjBscInfo(HttpServletRequest request,HttpServletResponse response){
		String logId = request.getParameter("id");
		String prjId = request.getParameter("prjId");
		String verdictStatus = request.getParameter("verdictStatus");//签约标识

		PrjBscInfoVO bscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String viewName = "";
		if(null != bscInfoVO ) {
			if (PrjBscInfoConstant.PRJ_INS_CODE_SN.equals(bscInfoVO.getInsCode())) {
				viewName = "checkSNPrjBscInfo";
			}else if (PrjBscInfoConstant.PRJ_INS_CODE_ZBBANK.equals(bscInfoVO.getInsCode())) {
				viewName = "checkZBPrjBscInfo";
			}else if (PrjBscInfoConstant.PRJ_INS_CODE_SNBANKS.equals(bscInfoVO.getInsCode())) {
				viewName = "checkSNBankPrjBscInfo";
			}else if (PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK.equals(bscInfoVO.getInsCode())) {
				viewName = "checkZGCPrjBscInfo";
			}else if (PrjBscInfoConstant.PRJ_INS_CODE_YLBANK.equals(bscInfoVO.getInsCode())) {
				viewName = "checkYlPrjBscInfo";
			}
		}
		ModelAndView view = new ModelAndView("institution/snbank/"+viewName);
		if(null != bscInfoVO ){
			view.addObject("lsCntNo", bscInfoVO.getLsCntNo());
		}
        PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
		prjCstAccInfoQueryCondition.setPrjId(Long.valueOf(prjId));
		prjCstAccInfoQueryCondition.setInsCode(bscInfoVO.getInsCode());
		List<PrjCstAccInfoDTO> prjCstAccInfoDTOS = this.prjCstAccInfoApiService.searchPrjCstAccInfoList(prjCstAccInfoQueryCondition);
		if (CollectionUtils.isNotEmpty(prjCstAccInfoDTOS)) {
			PrjCstAccInfoDTO prjCstAccInfoDTO = prjCstAccInfoDTOS.get(0);
			view.addObject("cstNm", prjCstAccInfoDTO.getCstNm());
			view.addObject("certNo", prjCstAccInfoDTO.getCertNo());
			view.addObject("bkNm", prjCstAccInfoDTO.getBkNm());
			view.addObject("accNo", prjCstAccInfoDTO.getAccNo());
			view.addObject("mp", prjCstAccInfoDTO.getMp());
			view.addObject("bkNo", prjCstAccInfoDTO.getBkNo());
		}

		view.addObject("logId", logId);
		view.addObject("prjId", prjId);
		view.addObject("verdictStatus", verdictStatus);
		return view;
	}
	//苏宁换卡
	@RequestMapping(value = "/exchangeCard.do", method = { RequestMethod.GET })
	public ModelAndView exchangeCard(HttpServletRequest request,HttpServletResponse response){
		String logId = request.getParameter("id");
		String prjId = request.getParameter("prjId");

		PrjBscInfoVO bscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		String viewName = "";
		List<BankInfo> bankList =  new ArrayList<>();
		if (null != bscInfoVO){
			if (PrjBscInfoConstant.PRJ_INS_CODE_SN.equals(bscInfoVO.getInsCode())){
				viewName = "exchangeCard";
				// 苏宁支持的银行列表
				//查询映射表 找到匹配一级产品类型 设置到查询条件里   :查询是用  prdTypCd like 'XX%'
				SysCdMapDQueryCondition cdMapDQC = new SysCdMapDQueryCondition();
				cdMapDQC.setSysCd(WebBaseConstant.SYS_SYS_CD);
				cdMapDQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
				cdMapDQC.setmTypCd("M1041");
				cdMapDQC.setTCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
				List<SysCdMapDDTO> sysCdMapDList =  this.sysCdMapApiService.searchSysCdMapDWithTargetList(cdMapDQC);
				if (CollectionUtils.isNotEmpty(sysCdMapDList)) {
					for(SysCdMapDDTO sysCdMapDDTO : sysCdMapDList) {
						String codeAttr1 = sysCdMapDDTO.getCodeAttr1();
						if(StringUtils.isNotBlank(codeAttr1)){
							BankInfo kv = new BankInfo();
							kv.setKey(sysCdMapDDTO.getSCode());
							kv.setValue(sysCdMapDDTO.getSCodeNm());
							bankList.add(kv);
						}
					}
				}
			}
			if (PrjBscInfoConstant.PRJ_INS_CODE_ZBBANK.equals(bscInfoVO.getInsCode())){
				viewName = "exchangeCardZB";
				List<SysDictionaryDTO> sysCdMapDList = this.prjCstAccInfoService.searchGroup(WebBaseConstant.SYS_SYS_CD,WebBaseConstant.SYS_P_ORG_CD,PrjCstAccInfoConstant.CODE_ZB_SUPPORT_BANK_CD);
				if (CollectionUtils.isNotEmpty(sysCdMapDList)) {
					for(SysDictionaryDTO sysDictionaryDTO : sysCdMapDList) {
						String codeAttr1 = sysDictionaryDTO.getCodeAttr1();
						if(StringUtils.isNotBlank(codeAttr1)){
							BankInfo kv = new BankInfo();
							kv.setKey(sysDictionaryDTO.getCode());
							kv.setValue(sysDictionaryDTO.getCodeNm());
							kv.setBankNumber(sysDictionaryDTO.getCodeAttr1());
							bankList.add(kv);
						}
					}
				}
			}
			if(PrjBscInfoConstant.PRJ_INS_CODE_SNBANKS.equals(bscInfoVO.getInsCode())){
                viewName = "exchangeCardSN";
				// 苏宁支持的银行列表
				//查询映射表 找到匹配一级产品类型 设置到查询条件里   :查询是用  prdTypCd like 'XX%'
				SysCdMapDQueryCondition cdMapDQC = new SysCdMapDQueryCondition();
				cdMapDQC.setSysCd(WebBaseConstant.SYS_SYS_CD);
				cdMapDQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
				cdMapDQC.setmTypCd("M1041");
				cdMapDQC.setTCode(PrjBscInfoConstant.PRJ_INS_CODE_SNBANKS);
				List<SysCdMapDDTO> sysCdMapDList =  this.sysCdMapApiService.searchSysCdMapDWithTargetList(cdMapDQC);
				if (CollectionUtils.isNotEmpty(sysCdMapDList)) {
					for(SysCdMapDDTO sysCdMapDDTO : sysCdMapDList) {
						String codeAttr1 = sysCdMapDDTO.getCodeAttr1();
						// if(StringUtils.isNotBlank(codeAttr1)){
							BankInfo kv = new BankInfo();
							kv.setKey(sysCdMapDDTO.getSCode());
							kv.setValue(sysCdMapDDTO.getSCodeNm());
							bankList.add(kv);
						// }
					}
				}
			}
			if(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK.equals(bscInfoVO.getInsCode())){
				viewName = "exchangeCardZGC";
				// 中关村支持的银行列表
				//查询映射表 找到匹配一级产品类型 设置到查询条件里   :查询是用  prdTypCd like 'XX%'
				SysCdMapDQueryCondition cdMapDQC = new SysCdMapDQueryCondition();
				cdMapDQC.setSysCd(WebBaseConstant.SYS_SYS_CD);
				cdMapDQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
				cdMapDQC.setmTypCd("M1041");
				cdMapDQC.setTCode(PrjBscInfoConstant.PRJ_INS_CODE_ZGCBANK);
				List<SysCdMapDDTO> sysCdMapDList =  this.sysCdMapApiService.searchSysCdMapDWithTargetList(cdMapDQC);
				if (CollectionUtils.isNotEmpty(sysCdMapDList)) {
					for(SysCdMapDDTO sysCdMapDDTO : sysCdMapDList) {
						BankInfo kv = new BankInfo();
						kv.setKey(sysCdMapDDTO.getSCode());
						kv.setValue(sysCdMapDDTO.getSCodeNm());
						bankList.add(kv);
					}
				}
			}
			if(PrjBscInfoConstant.PRJ_INS_CODE_YLBANK.equals(bscInfoVO.getInsCode())){
				viewName = "exchangeCardYl";
				SysCdMapDQueryCondition cdMapDQC = new SysCdMapDQueryCondition();
				cdMapDQC.setSysCd(WebBaseConstant.SYS_SYS_CD);
				cdMapDQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
				cdMapDQC.setmTypCd("M1041");
				cdMapDQC.setTCode(PrjBscInfoConstant.PRJ_INS_CODE_YLBANK);
				List<SysCdMapDDTO> sysCdMapDList =  this.sysCdMapApiService.searchSysCdMapDWithTargetList(cdMapDQC);
				if (CollectionUtils.isNotEmpty(sysCdMapDList)) {
					for(SysCdMapDDTO sysCdMapDDTO : sysCdMapDList) {
						BankInfo kv = new BankInfo();
						kv.setKey(sysCdMapDDTO.getSCode());
						kv.setValue(sysCdMapDDTO.getSCodeNm());
						bankList.add(kv);
					}
				}
			}
		}
		ModelAndView view = new ModelAndView("institution/snbank/"+viewName);
		if(null != bscInfoVO ){
			view.addObject("lsCntNo", bscInfoVO.getLsCntNo());//合同号
			view.addObject("fundRasInsId", bscInfoVO.getFundRasInsId());//机构id
		}
        PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
        prjCstAccInfoQueryCondition.setPrjId(Long.valueOf(prjId));
        prjCstAccInfoQueryCondition.setInsCode(bscInfoVO.getInsCode());
        List<PrjCstAccInfoDTO> prjCstAccInfoDTOS = this.prjCstAccInfoApiService.searchPrjCstAccInfoList(prjCstAccInfoQueryCondition);
        if (CollectionUtils.isNotEmpty(prjCstAccInfoDTOS)) {
            PrjCstAccInfoDTO prjCstAccInfoDTO = prjCstAccInfoDTOS.get(0);
			view.addObject("cstId", prjCstAccInfoDTO.getCstId());//客户姓名
			view.addObject("cstNm", prjCstAccInfoDTO.getCstNm());//客户姓名
			view.addObject("certNo", prjCstAccInfoDTO.getCertNo());//身份证号
			view.addObject("bkCd", prjCstAccInfoDTO.getBkCd());//开户银行
			view.addObject("accNo", prjCstAccInfoDTO.getAccNo());//银行账号
			view.addObject("mp", prjCstAccInfoDTO.getMp());//银行账号
			view.addObject("bkNo", prjCstAccInfoDTO.getBkNo());//开户行号
		}
		InfTransLogQueryCondition condition = new InfTransLogQueryCondition();
		condition.setId(Long.valueOf(logId));
		condition.setPrjId(Long.valueOf(prjId));
		List<InfTransLogDTO> transLogs = this.transLogApi.findTransLogs(condition);
		if(CollectionUtils.isNotEmpty(transLogs)){
			InfTransLogDTO logDTO = transLogs.get(0);
			if(null != logDTO){
				view.addObject("action", logDTO.getAction());
			}
		}
		view.addObject("bankList",bankList);
		view.addObject("logId", logId);
		view.addObject("prjId", prjId);
		return view;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getVerificationCode.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object getVerificationCode(PrjCstAccInfoQueryCondition prjCstAccInfoQC,Long fundRasInsId,String typeCd) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
		CustomerBankInfoDTO customerBankInfoDTO = new CustomerBankInfoDTO();

		BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
		/*PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjCstAccInfoQC.getPrjId());
		// Long prjCstAccid = null;
		if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
			// prjCstAccid = prjCstAccInfo.getId();
			prjCstAccInfoQC.setId(prjCstAccInfo.getId());
		}*/
        PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
        prjCstAccInfo.setPrjId(prjCstAccInfoQC.getPrjId());
        prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
        prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
        List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
		PrjCstAccInfoVO prjCstAccInfoVO = new PrjCstAccInfoVO();
        if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
            prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
        }
		// 设置证件类型
		prjCstAccInfoQC.setCertTypCd("01");
		//去验证四要素
		String certTypCd = null;
		String buOrgCd = null;
        prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
        // 四要素校验
		DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);

		// CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(prjCstAccInfoQC.getCstId());

		String chkRstCd = null, rstDesc = null;
		if(null != resultDTO && null != resultDTO.getData()){
			@SuppressWarnings("unchecked")
			Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
			chkRstCd = ckResMap.get("chkRstCd");
			rstDesc = ckResMap.get("rstDesc");
			BaseLogUtils.info(logger, "getVerificationCode", "检验结果,chkRstCd=" + chkRstCd);
			//验证返回结果成功
			if("1".equals(chkRstCd)) {
				//1.会员开户申请传输接口
				customerBankInfoDTO.setCustId(prjCstAccInfoQC.getCstId());//客户id
				customerBankInfoDTO.setCustName(prjCstAccInfoQC.getCstNm());//客户名称
				customerBankInfoDTO.setBankName(prjCstAccInfoQC.getBkCd());//银行代码
				customerBankInfoDTO.setBankCardNum(prjCstAccInfoQC.getAccNo());//银行账号
				customerBankInfoDTO.setPhone(prjCstAccInfoQC.getMp());//预留手机号
				customerBankInfoDTO.setIdNo(prjCstAccInfoQC.getCertNo());//身份证号
				customerBankInfoDTO.setTerminalType("31");//终端
				customerBankInfoDTO.setToken(getRandomIp()); // 默认随机
				customerBankInfoDTO.setIdType("01");//证件类型
				customerBankInfoDTO.setFlag(1);//区别第一次开户和之后换卡
				customerBankInfoDTO.setFundRasInsNm("苏宁银行");
				customerBankInfoDTO.setBuOrgCd(buOrgCd); // 事业部
				BaseLogUtils.info(logger, "getVerificationCode", "调苏宁会员开户申请传输接口Start,传输信息：" +JSONObject.toJSONString(customerBankInfoDTO));
				MessageDTO<String> messageDTO = this.snApi.createAccount(fundRasInsId, prjCstAccInfoQC.getPrjId(), customerBankInfoDTO);
				BaseLogUtils.info(logger, "getVerificationCode", "调苏宁会员开户申请传输接口End,传输信息：" +JSONObject.toJSONString(messageDTO));
				if (messageDTO.isSuccess()) {//messageDTO.isSuccess()
					BaseLogUtils.info(logger, "getVerificationCode", "开户失败 prjid=" + prjCstAccInfoQC.getPrjId() + ",code=" + messageDTO.getCode() + ",message=" + messageDTO.getMessage());
					//已经开户并签约
					if("E0009".equals(messageDTO.getCode())){//messageDTO.getCode()不需要短信验证码进行验证开户
						BaseLogUtils.info(logger, "getVerificationCode", "此用户已经开过成功无需短信验证开户,prjid=" + prjCstAccInfoQC.getPrjId());
						result.setSuccess(2);//去页面提示：该银行卡已签约，无需验证验证码，是否换卡？
					}else{
						//构造查询条件进行本地日志查询
						InfTransLogQueryCondition condition2 = new InfTransLogQueryCondition();
						condition2.setFundRasInsId(fundRasInsId);
						condition2.setPrjId(prjCstAccInfoQC.getPrjId());
						condition2.setAction(InterfaceConstants.Action.createAccount.key());
						BaseLogUtils.info(logger, "getVerificationCode", "本地日志查询Start,传输信息：" +JSONObject.toJSONString(condition2));
						List<InfTransLogDTO> dtos =  transLogApi.findTransLogs(condition2);
						BaseLogUtils.info(logger, "getVerificationCode", "本地日志查询End,传输信息：" +JSONObject.toJSONString(dtos));
						InfTransLogDTO transLog = null ;
						if (null != dtos && dtos.size() > 0) {
							transLog = dtos.get(0);
							//开户成功
							if(InterfaceConstants.TransStatus.success.key().equals(transLog.getStatus())){
								//开户成功保存换卡信息，先把之前存入的信息保存在 sys_ins_ivk_val（资管机构承接调用结果）  表 ,目的为了记录每一次换过的卡信息
								SysInsIvkValDTO sysInsIvkValDTO = new SysInsIvkValDTO();
								sysInsIvkValDTO.setPrjId(prjCstAccInfo.getPrjId());
								sysInsIvkValDTO.setInsId(fundRasInsId);
								sysInsIvkValDTO.setCstId(prjCstAccInfoVO.getCstId());
								sysInsIvkValDTO.setTypeCd(typeCd);
								sysInsIvkValDTO.setRespRule("mp:"+prjCstAccInfoVO.getMp()+";"+"certNo:"+prjCstAccInfoVO.getCertNo()+";"+"accNo:"+prjCstAccInfoVO.getAccNo()+";"+"accNm:"+prjCstAccInfoVO.getAccNm()+";"+"bkCd:"+prjCstAccInfoVO.getBkCd()+";"+"bkNm:"+prjCstAccInfoVO.getBkNm()+";"+"bkNo:"+prjCstAccInfoVO.getBkNo());
								sysInsIvkValDTO.setCrtTm(new Date());
								BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录Strat： sysInsIvkValDTO = " + JSONObject.toJSONString(sysInsIvkValDTO));
								Long add = this.sysInsIvkValApiService.add(sysInsIvkValDTO);
								BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录End： 保存sysInsIvkValDTO返回值 = " + JSONObject.toJSONString(add));

								BaseLogUtils.info(logger, "getVerificationCode", "开户成功 prjid=" + prjCstAccInfo.getPrjId()+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
								result.setSuccess(BaseConstant.IS_YESNO_YES);
								result.setInfo("验证码已发送承租人，请联系客户获取");
							}else{//开户失败
								result.setSuccess(BaseConstant.IS_YESNO_NO);
								result.setInfo(messageDTO.getMessage());
							}
						}else{
							BaseLogUtils.info(logger, "getVerificationCode", "查询开户接口日志为空,prjid=" + prjCstAccInfo.getPrjId());
							result.setSuccess(BaseConstant.IS_YESNO_NO);
							result.setInfo("开户失败,查询开户接口日志为空:"+messageDTO.getMessage());
						}
					}
				}
			} else {//验证失败
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("四要素信息校验未通过，请核查四要素"+"校验结果:"+rstDesc);
            }
		}else{
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("四要素信息校验异常");
		}
		return result;
	}

	//获取验证码
	@SuppressWarnings("unused")
	@RequestMapping(value = "/getVerificationCodeOld.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object getVerificationCodeOld(Long prjId, HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
		PrjCstAccInfoQueryCondition prjCstAccInfoQC = new PrjCstAccInfoQueryCondition();//项目客户账户信息
		CustomerBankInfoDTO customerBankInfoDTO = new CustomerBankInfoDTO();
		String cstId = request.getParameter("cstId"); // 客户ID
		String bkCd = request.getParameter("bkCd"); //开户行号
		String accNo = request.getParameter("accNo"); //银行账号
		String cstNm = request.getParameter("cstNm"); //账号名称
		String fundRasInsId = request.getParameter("fundRasInsId"); //机构id
		String typeCd = request.getParameter("typeCd"); //接口类型
		String certNo = request.getParameter("certNo"); //身份证号
		String bkNm = request.getParameter("bkNm"); //银行名称
		String mp = request.getParameter("mp"); //预留手机号
		String bkNo = request.getParameter("bkNo"); //开户行号

		try {
			if(StringUtils.isNotBlank(cstNm)){
				prjCstAccInfoQC.setAccNm(cstNm);
			}
			if(StringUtils.isNotBlank(bkCd)){
				prjCstAccInfoQC.setBkCd(bkCd);
			}
			if(StringUtils.isNotBlank(accNo)){
				prjCstAccInfoQC.setAccNo(accNo);
			}

			if(StringUtils.isNotBlank(cstNm)){
				prjCstAccInfoQC.setCstNm(cstNm);
			}
			if(StringUtils.isNotBlank(bkNm)){
				prjCstAccInfoQC.setBkNm(bkNm);
			}
			if(StringUtils.isNotBlank(mp)){
				prjCstAccInfoQC.setMp(mp);
			}
			if(StringUtils.isNotBlank(bkNo)){
				prjCstAccInfoQC.setBkNo(bkNo);
			}
			prjCstAccInfoQC.setPrjId(Long.valueOf(prjId));
			prjCstAccInfoQC.setCstId(Long.valueOf(cstId));
			prjCstAccInfoQC.setCertNo(certNo);
			BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
			/*PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjId);
			Long prjCstAccid = null;
			if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
				prjCstAccid = prjCstAccInfo.getId();
				prjCstAccInfoQC.setId(prjCstAccid);
				prjCstAccInfoQC.setCertTypCd(prjCstAccInfo.getCertTypCd());// 客户证件类型
			}*/
            PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
            prjCstAccInfo.setPrjId(prjId);
            prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
			PrjCstAccInfoVO prjCstAccInfoVO = new PrjCstAccInfoVO();
            if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
                prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
                prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
                prjCstAccInfoQC.setCertTypCd(prjCstAccInfo.getCertTypCd());// 客户证件类型
            }
			//去验证四要素
			String certTypCd = null;
			String buOrgCd = null;
            prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
            DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);
			CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(Long.valueOf(cstId));
			String chkRstCd = null, rstDesc = null;
			if(null != resultDTO && null != resultDTO.getData()){
				@SuppressWarnings("unchecked")
				Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
				chkRstCd = ckResMap.get("chkRstCd");
				rstDesc = ckResMap.get("rstDesc");
				BaseLogUtils.info(logger, "getVerificationCode", "检验结果,chkRstCd=" + chkRstCd);
				if(chkRstCd.equals("1")){//验证返回结果成功
					//1.会员开户申请传输接口
					customerBankInfoDTO.setCustId(Long.valueOf(cstId));//客户id
					customerBankInfoDTO.setCustName(prjCstAccInfo.getCstNm());//客户名称
					customerBankInfoDTO.setBankName(bkCd);//银行代码
					customerBankInfoDTO.setBankCardNum(accNo);//银行账号
					customerBankInfoDTO.setPhone(mp);//预留手机号
					customerBankInfoDTO.setIdNo(certNo);//身份证号
					customerBankInfoDTO.setTerminalType("31");//终端
					customerBankInfoDTO.setToken(getRandomIp()); // 默认随机
					customerBankInfoDTO.setIdType("01");//证件类型
					customerBankInfoDTO.setFlag(1);//区别第一次开户和之后换卡
					customerBankInfoDTO.setFundRasInsNm("苏宁银行");
					customerBankInfoDTO.setBuOrgCd(buOrgCd); // 事业部
					BaseLogUtils.info(logger, "getVerificationCode", "调苏宁会员开户申请传输接口Start,传输信息：" +JSONObject.toJSONString(customerBankInfoDTO));
					MessageDTO<String> messageDTO = this.snApi.createAccount(Long.valueOf(fundRasInsId), Long.valueOf(prjId), customerBankInfoDTO);
					BaseLogUtils.info(logger, "getVerificationCode", "调苏宁会员开户申请传输接口End,传输信息：" +JSONObject.toJSONString(messageDTO));
					if (messageDTO.isSuccess()) {//messageDTO.isSuccess()
						BaseLogUtils.info(logger, "getVerificationCode", "开户失败 prjid=" + prjId+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
						//已经开户并签约
						if("E0009".equals(messageDTO.getCode())){//messageDTO.getCode()不需要短信验证码进行验证开户
							BaseLogUtils.info(logger, "getVerificationCode", "此用户已经开过成功无需短信验证开户,prjid=" + prjId);
							result.setSuccess(2);//去页面提示：该银行卡已签约，无需验证验证码，是否换卡？
						}else{
							//构造查询条件进行本地日志查询
							InfTransLogQueryCondition condition2 = new InfTransLogQueryCondition();
							condition2.setFundRasInsId(Long.valueOf(fundRasInsId));
							condition2.setPrjId(Long.valueOf(prjId));
							condition2.setAction(InterfaceConstants.Action.createAccount.key());
							BaseLogUtils.info(logger, "getVerificationCode", "本地日志查询Start,传输信息：" +JSONObject.toJSONString(condition2));
							List<InfTransLogDTO> dtos =  transLogApi.findTransLogs(condition2);
							BaseLogUtils.info(logger, "getVerificationCode", "本地日志查询End,传输信息：" +JSONObject.toJSONString(dtos));
							InfTransLogDTO transLog = null ;
							if (null != dtos && dtos.size() > 0) {
								transLog = dtos.get(0);
								//开户成功
								if(InterfaceConstants.TransStatus.success.key().equals(transLog.getStatus())){
									//开户成功保存换卡信息，先把之前存入的信息保存在 sys_ins_ivk_val（资管机构承接调用结果）  表 ,目的为了记录每一次换过的卡信息
									SysInsIvkValDTO sysInsIvkValDTO = new SysInsIvkValDTO();
									sysInsIvkValDTO.setPrjId(prjCstAccInfo.getPrjId());
									sysInsIvkValDTO.setInsId(Long.valueOf(fundRasInsId));
									sysInsIvkValDTO.setCstId(prjCstAccInfoVO.getCstId());
									sysInsIvkValDTO.setTypeCd(typeCd);
									sysInsIvkValDTO.setRespRule("mp:"+prjCstAccInfoVO.getMp()+";"+"certNo:"+prjCstAccInfoVO.getCertNo()+";"+"accNo:"+prjCstAccInfoVO.getAccNo()+";"+"accNm:"+prjCstAccInfoVO.getAccNm()+";"+"bkCd:"+prjCstAccInfoVO.getBkCd()+";"+"bkNm:"+prjCstAccInfoVO.getBkNm()+";"+"bkNo:"+prjCstAccInfoVO.getBkNo());
									sysInsIvkValDTO.setCrtTm(new Date());
									BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录Strat： sysInsIvkValDTO = " + JSONObject.toJSONString(sysInsIvkValDTO));
									Long add = this.sysInsIvkValApiService.add(sysInsIvkValDTO);
									BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录End： 保存sysInsIvkValDTO返回值 = " + JSONObject.toJSONString(add));
									//更新数据
									prjCstAccInfoQC.setCheckResult(chkRstCd);
                                    prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
									DataResultDTO resultDTO1 = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
									BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息End： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
									if(null != resultDTO1){
										@SuppressWarnings("unchecked")
										Map<String, String> ckResMap1 = (Map<String, String>) resultDTO.getData();
										chkRstCd = ckResMap1.get("chkRstCd");
										rstDesc = ckResMap1.get("rstDesc");
										if(chkRstCd.equals("1")){//更新校验成功
											PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
											result.setSuccess(BaseConstant.IS_YESNO_YES);
											result.setInfo("修改成功，客户在+"+prjBscInfoVO.getFundRasInsNm()+"+还款银行卡已修改；");
										}else{
											result.setSuccess(2);
											result.setInfo("四要素信息校验未通过，请核查四要素"+"更新数据后校验结果："+chkRstCd);
										}

									}
									BaseLogUtils.info(logger, "getVerificationCode", "开户成功 prjid=" + prjId+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
									result.setSuccess(BaseConstant.IS_YESNO_YES);
									result.setInfo("验证码已发送承租人，请联系客户获取");
								}else{//开户失败
									result.setSuccess(BaseConstant.IS_YESNO_NO);
									result.setInfo(messageDTO.getMessage());
								}
							}else{
								BaseLogUtils.info(logger, "getVerificationCode", "查询开户接口日志为空,prjid=" + prjId);
								result.setSuccess(BaseConstant.IS_YESNO_NO);
								result.setInfo("开户失败,查询开户接口日志为空:"+messageDTO.getMessage());
							}
						}
					}
				}else if(chkRstCd.equals("0") || chkRstCd.equals("2")){//验证失败
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("四要素信息校验未通过，请核查四要素"+"校验结果:"+chkRstCd);
				}
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("四要素信息校验异常");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("保存失败!");
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		return result;
	}
	//不需要获取验证码，换卡
	@SuppressWarnings("unused")
	@RequestMapping(value = "/exchangeCardOne.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object exchangeCardOne(Long prjId, HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
		PrjCstAccInfoQueryCondition prjCstAccInfoQC = new PrjCstAccInfoQueryCondition();//项目客户账户信息
		CustomerBankInfoDTO customerBankInfoDTO = new CustomerBankInfoDTO();
		String cstId = request.getParameter("cstId"); // 客户ID
		String bkCd = request.getParameter("bkCd"); //开户行号
		String accNo = request.getParameter("accNo"); //银行账号
		String cstNm = request.getParameter("cstNm"); //账号名称
		String fundRasInsId = request.getParameter("fundRasInsId"); //机构id
		String typeCd = request.getParameter("typeCd"); //接口类型
		String certNo = request.getParameter("certNo"); //身份证号
		String bkNm = request.getParameter("bkNm"); //银行名称
		String mp = request.getParameter("mp"); //预留手机号
		String bkNo = request.getParameter("bkNo"); //开户行号
		try {
			if(StringUtils.isNotBlank(cstNm)){
				prjCstAccInfoQC.setAccNm(cstNm);
			}
			if(StringUtils.isNotBlank(bkCd)){
				prjCstAccInfoQC.setBkCd(bkCd);
			}
			if(StringUtils.isNotBlank(accNo)){
				prjCstAccInfoQC.setAccNo(accNo);
			}

			if(StringUtils.isNotBlank(cstNm)){
				prjCstAccInfoQC.setCstNm(cstNm);
			}
			if(StringUtils.isNotBlank(bkNm)){
				prjCstAccInfoQC.setBkNm(bkNm);
			}
			if(StringUtils.isNotBlank(mp)){
				prjCstAccInfoQC.setMp(mp);
			}
			if(StringUtils.isNotBlank(bkNo)){
				prjCstAccInfoQC.setBkNo(bkNo);
			}
			prjCstAccInfoQC.setPrjId(Long.valueOf(prjId));
			prjCstAccInfoQC.setCstId(Long.valueOf(cstId));
			prjCstAccInfoQC.setCertNo(certNo);
			BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
			/*PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjId);
			Long prjCstAccid = null;
			if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
				prjCstAccid = prjCstAccInfo.getId();
				prjCstAccInfoQC.setId(prjCstAccid);
			}*/
            PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
            prjCstAccInfo.setPrjId(prjId);
            prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
            if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
                PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
                prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
            }
			prjCstAccInfoQC.setCertTypCd("01");
            prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
            //去验证四要素
			DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);
			String chkRstCd = null, rstDesc = null;
			if(null != resultDTO && null != resultDTO.getData()){
				@SuppressWarnings("unchecked")
				Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
				chkRstCd = ckResMap.get("chkRstCd");
				rstDesc = ckResMap.get("rstDesc");
				if(chkRstCd.equals("1")){//验证返回结果成功
					//调绑卡接口
					customerBankInfoDTO.setCustId(Long.valueOf(cstId));//客户id
					customerBankInfoDTO.setCustName(prjCstAccInfo.getCstNm());//客户名称
					customerBankInfoDTO.setBankName(bkCd);//银行代码
					customerBankInfoDTO.setBankCardNum(accNo);//银行账号
					customerBankInfoDTO.setPhone(mp);//预留手机号
					customerBankInfoDTO.setIdNo(certNo);//身份证号
					BaseLogUtils.info(logger, "exchangeCardOne", "调换绑卡接口Strat： customerBankInfoDTO = " + JSONObject.toJSONString(customerBankInfoDTO));
					MessageDTO<String> bankCard = this.snApi.changeBankCard(Long.valueOf(fundRasInsId), Long.valueOf(prjId), customerBankInfoDTO);
					BaseLogUtils.info(logger, "exchangeCardOne", "调换绑卡接口End： customerBankInfoDTO = " + JSONObject.toJSONString(bankCard));
					if("01".equals(bankCard.getCode())){//换绑卡成功bankCard.getCode()
						//保存换卡信息，先把之前存入的信息保存在 sys_ins_ivk_val（资管机构承接调用结果）  表 ,目的为了记录每一次换过的卡信息
						SysInsIvkValDTO sysInsIvkValDTO = new SysInsIvkValDTO();
						sysInsIvkValDTO.setPrjId(prjCstAccInfo.getPrjId());
						sysInsIvkValDTO.setInsId(Long.valueOf(fundRasInsId));
						sysInsIvkValDTO.setCstId(prjCstAccInfo.getCstId());
						sysInsIvkValDTO.setTypeCd(typeCd);
						sysInsIvkValDTO.setRespRule("mp:"+prjCstAccInfo.getMp()+";"+"certNo:"+prjCstAccInfo.getCertNo()+";"+"accNo:"+prjCstAccInfo.getAccNo()+";"+"accNm:"+prjCstAccInfo.getAccNm()+";"+"bkCd:"+prjCstAccInfo.getBkCd()+";"+"bkNm:"+prjCstAccInfo.getBkNm()+";"+"bkNo:"+prjCstAccInfo.getBkNo());
						sysInsIvkValDTO.setCrtTm(new Date());
						BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录Strat： sysInsIvkValDTO = " + JSONObject.toJSONString(sysInsIvkValDTO));
						Long add = this.sysInsIvkValApiService.add(sysInsIvkValDTO);
						BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录End： 保存sysInsIvkValDTO返回值 = " + JSONObject.toJSONString(add));
						//更新数据
                        prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
						DataResultDTO resultDTO1 = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
						BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息End： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
						if(null != resultDTO1){
							@SuppressWarnings("unchecked")
							Map<String, String> ckResMap1 = (Map<String, String>) resultDTO.getData();
							chkRstCd = ckResMap1.get("chkRstCd");
							rstDesc = ckResMap1.get("rstDesc");
							if(chkRstCd.equals("1")){//更新校验成功
								PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
								result.setSuccess(BaseConstant.IS_YESNO_YES);
								result.setInfo("修改成功，客户在+"+prjBscInfoVO.getFundRasInsNm()+"+还款银行卡已修改；");
							}else{
								result.setSuccess(2);
								result.setInfo("四要素信息校验未通过，请核查四要素"+"更新数据后校验结果"+chkRstCd);
							}

						}

					}else{//换绑卡失败
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo("换卡失败，请联系客户核实银行卡和预留手机号信息");
					}

				}else if(chkRstCd.equals("0") || chkRstCd.equals("2")){//验证失败
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("四要素信息校验未通过，请核查四要素");
				}
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("四要素信息校验异常");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("保存失败!");
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		return result;
	}

	/**
	 *  众邦换卡
	 * @param prjCstAccInfoQC
	 * @param fundRasInsId
	 * @param typeCd
	 * @return
	 * @throws BaseException
	 */
	@SuppressWarnings("unused")
	@RequestMapping(value = "/exchangeCardZBSave.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object exchangeCardZBSave(PrjCstAccInfoQueryCondition prjCstAccInfoQC,Long fundRasInsId,String typeCd) throws BaseException{
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
		BaseLogUtils.info(logger, "exchangeCardZBSave", "换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
		/*PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjCstAccInfoQC.getPrjId());
		if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
			prjCstAccInfoQC.setId(prjCstAccInfo.getId());
		}*/
        PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
        prjCstAccInfo.setPrjId(prjCstAccInfoQC.getPrjId());
        prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
        prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZBBANK);
        List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
        if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
        }
		// 设置证件类型
		prjCstAccInfoQC.setCertTypCd("0");
		prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZBBANK);
		try {
			//去验证四要素
			String buOrgCd = null;
			// 四要素校验
			DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);
			BaseLogUtils.info(logger, "exchangeCardZBSave", "四要素校验结果： resultDTO = " + JSONObject.toJSONString(resultDTO));
			String chkRstCd = null, rstDesc = null;
			String bankCardType = null;
            if (resultDTO != null){
                if (resultDTO.getData() != null  && BaseConstant.IS_YESNO_YES_STR.equals(resultDTO.getCode())){
					Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
					chkRstCd = ckResMap.get("chkRstCd");
					rstDesc = ckResMap.get("rstDesc");
					bankCardType = ckResMap.get("bankCardType");
                    if(!"1".equals(chkRstCd)) {
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo(rstDesc);
						return result;
					}
					if (!"0".equals(bankCardType)){
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo("不支持此类银行卡，请更换为借记卡");
						return result;
					}
                    //验证返回结果成功
					if("1".equals(chkRstCd)) {
						CstAccDTO cstAccDTO = new CstAccDTO();
						cstAccDTO.setAcctNo(prjCstAccInfoQC.getAccNo());
						cstAccDTO.setAcctOpnAcctBnkNm(prjCstAccInfoQC.getBkNm());
						cstAccDTO.setMblNo(prjCstAccInfoQC.getMp());
						cstAccDTO.setOpnBakNo(prjCstAccInfoQC.getBkNo());
						BaseLogUtils.info(logger, "exchangeCardZBSave", "众邦换卡参数--客户信息： cstAccDTO = " + JSONObject.toJSONString(cstAccDTO));
						BaseLogUtils.info(logger, "exchangeCardZBSave", "项目id： prjId = " + prjCstAccInfoQC.getPrjId());
						BaseLogUtils.info(logger, "exchangeCardZBSave", "机构id： fundRasInsId = " + fundRasInsId);
						MessageDTO<InterfaceConstants.AuditResult> messageDTO = this.zbBankApi.changeBankCard(fundRasInsId,prjCstAccInfoQC.getPrjId(),cstAccDTO);
						BaseLogUtils.info(logger, "exchangeCardZBSave", "众邦换卡返回结果： messageDTO = " + JSONObject.toJSONString(messageDTO));
						if (messageDTO!= null){
							if (messageDTO.getData() == null){
								result.setSuccess(BaseConstant.IS_YESNO_NO);
								result.setInfo(messageDTO.getMessage());
								return result;
							}
							InterfaceConstants.AuditResult auditResult = messageDTO.getData();
							if ("pass".equals(auditResult.key())){
								prjCstAccInfoQC.setChkRstCd(chkRstCd);
								prjCstAccInfoQC.setBankCardTypeCd(bankCardType);
								BaseLogUtils.info(logger, "exchangeCardZBSave", "换卡保存 项目客户账户信息End： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
								//更新数据
                                prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_ZBBANK);
								DataResultDTO resultDTO1 = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
								result.setSuccess(BaseConstant.IS_YESNO_YES);
								result.setInfo("换卡成功");
								BaseLogUtils.info(logger, "exchangeCardZBSave", "换卡保存 返回信息： resultDTO1 = " + JSONObject.toJSONString(resultDTO1));
								BaseLogUtils.info(logger, "exchangeCardZBSave", "返回页面的信息： result = " + JSONObject.toJSONString(result));
								return result;
							}else {
								result.setSuccess(BaseConstant.IS_YESNO_NO);
								result.setInfo(messageDTO.getMessage());
								return result;
							}
						}

					}
				}

			}else {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(resultDTO.getInfo());
				return result;
			}

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("保存失败!");
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}

		return result;
	}
    //验证并换卡
    @SuppressWarnings("unused")
    @RequestMapping(value = "/exchangeCardSave.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object exchangeCardSave(PrjCstAccInfoQueryCondition prjCstAccInfoQC,Long fundRasInsId,String typeCd,String verificationCode) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
        CustomerBankInfoDTO customerBankInfoDTO = new CustomerBankInfoDTO();
        BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
        /*PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjCstAccInfoQC.getPrjId());
        // Long prjCstAccid = null;
        if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
            // prjCstAccid = prjCstAccInfo.getId();
            prjCstAccInfoQC.setId(prjCstAccInfo.getId());
        }*/
        PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
        prjCstAccInfo.setPrjId(prjCstAccInfoQC.getPrjId());
        prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
        prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
        List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
        if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
        }
        // 设置证件类型
        prjCstAccInfoQC.setCertTypCd("01");
        prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);

        try {
            //去验证四要素
            String certTypCd = null;
            String buOrgCd = null;
            // 四要素校验
            DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);
            String chkRstCd = null, rstDesc = null;

            if(null != resultDTO && null != resultDTO.getData()){
                @SuppressWarnings("unchecked")
                Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
                chkRstCd = ckResMap.get("chkRstCd");
                rstDesc = ckResMap.get("rstDesc");
                BaseLogUtils.info(logger, "getVerificationCode", "检验结果,chkRstCd=" + chkRstCd);
                //验证返回结果成功
                if("1".equals(chkRstCd)) {
                    //调会员短信验证接口
                    CustomerBankInfoDTO snApiDto = new CustomerBankInfoDTO();
                    snApiDto.setUserNo(prjCstAccInfoQC.getAccNo()); // 项目客户户头号
                    snApiDto.setPhoneCode(verificationCode); // 验证码
                    snApiDto.setTerminalType("31"); //pc
                    snApiDto.setToken(getRandomIp()); // 默认随机
                    snApiDto.setFlag(1);//区别第一次短信验证和换卡短信验证
                    BaseLogUtils.info(logger, "exchangeCardSave", "调用短信验证开户接口返回对象 ,机构id：" + fundRasInsId+ "项目ID：" + prjCstAccInfoQC.getPrjId() + JSON.toJSONString(snApiDto));
                    MessageDTO messageDTO = this.snApi.signAccount(fundRasInsId,prjCstAccInfoQC.getPrjId(), snApiDto);
                    BaseLogUtils.info(logger, "exchangeCardSave", "调用短信验证开户接口返回对象 ,机构id：" + fundRasInsId+ "项目ID：" + prjCstAccInfoQC.getPrjId() + JSON.toJSONString(messageDTO));

                    BaseLogUtils.info(logger, "exchangeCardSave", "短信验证开户接口返回对象：messageDTO：" + JSON.toJSONString(messageDTO));
                    boolean saveInfoFlag = false;
                    String respCode = "";
                    String respDesc = "";
                    // 短信验证开户
                    Map m = new HashMap();
                    if (null != messageDTO){
                        if (messageDTO.isSuccess()){
                            //构造查询条件进行本地日志查询
                            InfTransLogQueryCondition conditionInfT = new InfTransLogQueryCondition();
                            conditionInfT.setFundRasInsId(fundRasInsId);
                            conditionInfT.setPrjId(prjCstAccInfoQC.getPrjId());
                            conditionInfT.setAction(InterfaceConstants.Action.signAccount.key());
                            List<InfTransLogDTO> dtos =  transLogApi.findTransLogs(conditionInfT);
                            InfTransLogDTO transLog = null ;
                            if (null != dtos && dtos.size() > 0) {
                                transLog = dtos.get(0);
                                String status = transLog.getStatus();
                                if(InterfaceConstants.TransStatus.success.key().equals(status)) {//短信验证成功
                                    BaseLogUtils.info(logger, "exchangeCardSave", "短信验证成功,prjid=" + prjCstAccInfoQC.getPrjId()+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
                                    //调绑卡接口
                                    customerBankInfoDTO.setCustId(prjCstAccInfoQC.getCstId());//客户id
                                    customerBankInfoDTO.setCustName(prjCstAccInfo.getCstNm());//客户名称
                                    customerBankInfoDTO.setBankName(prjCstAccInfoQC.getBkCd());//银行代码
                                    customerBankInfoDTO.setBankCardNum(prjCstAccInfoQC.getAccNo());//银行账号
                                    customerBankInfoDTO.setPhone(prjCstAccInfoQC.getMp());//预留手机号
                                    customerBankInfoDTO.setIdNo(prjCstAccInfoQC.getCertNo());//身份证号
                                    MessageDTO<String> bankCard = this.snApi.changeBankCard(Long.valueOf(fundRasInsId), prjCstAccInfoQC.getPrjId(), customerBankInfoDTO);
                                    if("01".equals(bankCard.getCode())){//换绑卡成功bankCard.getCode()
                                        result.setSuccess(BaseConstant.IS_YESNO_YES);
                                        result.setInfo("换卡成功");
                                        //保存换卡信息，先把之前存入的信息保存在 sys_ins_ivk_val（资管机构承接调用结果）  表 ,目的为了记录每一次换过的卡信息
                                        SysInsIvkValDTO sysInsIvkValDTO = new SysInsIvkValDTO();
                                        sysInsIvkValDTO.setPrjId(prjCstAccInfo.getPrjId());
                                        sysInsIvkValDTO.setInsId(fundRasInsId);
                                        sysInsIvkValDTO.setCstId(prjCstAccInfo.getCstId());
                                        sysInsIvkValDTO.setTypeCd(typeCd);
                                        sysInsIvkValDTO.setRespRule("mp:"+prjCstAccInfo.getMp()+";"+"certNo:"+prjCstAccInfo.getCertNo()+";"+"accNo:"+prjCstAccInfo.getAccNo()+";"+"accNm:"+prjCstAccInfo.getAccNm()+";"+"bkCd:"+prjCstAccInfo.getBkCd()+";"+"bkNm:"+prjCstAccInfo.getBkNm()+";"+"bkNo:"+prjCstAccInfo.getBkNo());
                                        sysInsIvkValDTO.setCrtTm(new Date());
                                        BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录Strat： sysInsIvkValDTO = " + JSONObject.toJSONString(sysInsIvkValDTO));
                                        Long add = this.sysInsIvkValApiService.add(sysInsIvkValDTO);
                                        BaseLogUtils.info(logger, "save", "换卡之前保存换卡记录End： 保存sysInsIvkValDTO返回值 = " + JSONObject.toJSONString(add));
                                        //更新数据
                                        prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
                                        DataResultDTO resultDTO1 = this.prjCstAccInfoApiService.modifyPrjAccInfo(prjCstAccInfoQC);
                                        BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息End： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));

                                    }else{//换绑卡失败
                                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                                        //result.setInfo(bankCard.getMessage());
                                        result.setInfo("换卡失败，请联系客户核实银行卡和预留手机号信息");
                                    }
                                }else{//短信验证失败
                                    BaseLogUtils.info(logger, "getSignAccount", "短信验证失败,prjid=" + prjCstAccInfoQC.getPrjId()+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
                                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                                    result.setInfo("短信验证失败");
                                }
                            }else{
                                BaseLogUtils.info(logger, "getSignAccount", "查询短信验证接口数据为空,prjid=" +prjCstAccInfoQC.getPrjId());
                                result.setSuccess(BaseConstant.IS_YESNO_NO);
                                result.setInfo("验证开户失败,查询短信验证接口数据为空");
                            }
                        }else{//短信验证失败
                            BaseLogUtils.info(logger, "getSignAccount", "短信验证失败,prjid=" + prjCstAccInfoQC.getPrjId()+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
                            result.setSuccess(BaseConstant.IS_YESNO_NO);
                            result.setInfo("验证码有误，请核实");
                        }
                    }else {
                        BaseLogUtils.info(logger, "exchangeCardSave", "短信验证开户接口返回对象为空：prjID：" + prjCstAccInfoQC.getPrjId());
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        result.setInfo("短信验证开户接口返回对象为空");
                    }


                }else if(chkRstCd.equals("0") || chkRstCd.equals("2")){//验证失败
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("四要素信息校验未通过，请核查四要素");
                }
            }else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("四要素信息校验异常");
			}
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
            ex.printStackTrace();
        }
        catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("保存失败!");
            BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
            ex.printStackTrace();
        }

        return result;
    }
	//验证并换卡
	@SuppressWarnings("unused")
	@RequestMapping(value = "/exchangeCardSaveOld.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object exchangeCardSaveOld(Long prjId, HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "四要素校验通过");
		PrjCstAccInfoQueryCondition prjCstAccInfoQC = new PrjCstAccInfoQueryCondition();//项目客户账户信息
		CustomerBankInfoDTO customerBankInfoDTO = new CustomerBankInfoDTO();
		String cstId = request.getParameter("cstId"); // 客户ID
		String bkCd = request.getParameter("bkCd"); //开户行号
		String accNo = request.getParameter("accNo"); //银行账号
		String cstNm = request.getParameter("cstNm"); //账号名称
		String fundRasInsId = request.getParameter("fundRasInsId"); //机构id
		String typeCd = request.getParameter("typeCd"); //接口类型
		String certNo = request.getParameter("certNo"); //身份证号
		String bkNm = request.getParameter("bkNm"); //银行名称
		String mp = request.getParameter("mp"); //预留手机号
		String bkNo = request.getParameter("bkNo"); //预留手机号
		String verificationCode = request.getParameter("verificationCode"); //验证码

		try {
			if(StringUtils.isNotBlank(cstNm)){
				prjCstAccInfoQC.setAccNm(cstNm);
			}
			if(StringUtils.isNotBlank(bkCd)){
				prjCstAccInfoQC.setBkCd(bkCd);
			}
			if(StringUtils.isNotBlank(accNo)){
				prjCstAccInfoQC.setAccNo(accNo);
			}

			if(StringUtils.isNotBlank(cstNm)){
				prjCstAccInfoQC.setCstNm(cstNm);
			}
			if(StringUtils.isNotBlank(bkNm)){
				prjCstAccInfoQC.setBkNm(bkNm);
			}
			if(StringUtils.isNotBlank(mp)){
				prjCstAccInfoQC.setMp(mp);
			}
			if(StringUtils.isNotBlank(bkNo)){
				prjCstAccInfoQC.setBkNo(bkNo);
			}
			prjCstAccInfoQC.setPrjId(Long.valueOf(prjId));
			prjCstAccInfoQC.setCstId(Long.valueOf(cstId));
			prjCstAccInfoQC.setCertNo(certNo);
			BaseLogUtils.info(logger, "save", "换卡保存 项目客户账户信息Strat： prjCstAccInfoQC = " + JSONObject.toJSONString(prjCstAccInfoQC));
			/*PrjCstAccInfoVO prjCstAccInfo = this.prjCstAccInfoService.selectByPrjId(prjId);
			Long prjCstAccid = null;
			if(null != prjCstAccInfo && null != prjCstAccInfo.getId()){
				prjCstAccid = prjCstAccInfo.getId();
				prjCstAccInfoQC.setId(prjCstAccid);
			}*/
            PrjCstAccInfoQueryCondition prjCstAccInfo = new PrjCstAccInfoQueryCondition();
            prjCstAccInfo.setPrjId(prjId);
            prjCstAccInfo.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfo.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfo);
            if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
                PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
                prjCstAccInfoQC.setId(prjCstAccInfoVO.getId());
            }
            prjCstAccInfoQC.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SN);
			//去验证四要素
			DataResultDTO resultDTO = this.prjCstAccInfoApiService.snVerifyModifyPrjAccInfo(prjCstAccInfoQC);
			String chkRstCd = null, rstDesc = null;
			if(null != resultDTO && null != resultDTO.getData()){
				@SuppressWarnings("unchecked")
				Map<String, String> ckResMap = (Map<String, String>) resultDTO.getData();
				chkRstCd = ckResMap.get("chkRstCd");
				rstDesc = ckResMap.get("rstDesc");
				if(chkRstCd.equals("1")){//验证返回结果成功
					//调会员短信验证接口
					CustomerBankInfoDTO snApiDto = new CustomerBankInfoDTO();
					snApiDto.setUserNo(accNo); // 项目客户户头号
					snApiDto.setPhoneCode(verificationCode); // 验证码
					snApiDto.setTerminalType("31"); //pc
					snApiDto.setToken(getRandomIp()); // 默认随机
					snApiDto.setFlag(1);//区别第一次短信验证和换卡短信验证
					BaseLogUtils.info(logger, "exchangeCardSave", "调用短信验证开户接口返回对象 ,机构id：" + fundRasInsId+ "项目ID：" + prjId + JSON.toJSONString(snApiDto));
					MessageDTO messageDTO = this.snApi.signAccount(Long.valueOf(fundRasInsId),Long.valueOf(prjId), snApiDto);
					BaseLogUtils.info(logger, "exchangeCardSave", "调用短信验证开户接口返回对象 ,机构id：" + fundRasInsId+ "项目ID：" + prjId + JSON.toJSONString(messageDTO));
					if (null == messageDTO) {
						BaseLogUtils.info(logger, "exchangeCardSave", "短信验证开户接口返回对象为空：prjID：" + prjId);
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo("短信验证开户接口返回对象为空");
					}
					BaseLogUtils.info(logger, "exchangeCardSave", "短信验证开户接口返回对象：messageDTO：" + JSON.toJSONString(messageDTO));
					boolean saveInfoFlag = false;
					String respCode = "";
					String respDesc = "";
					// 短信验证开户
					Map m = new HashMap();
					if (messageDTO.isSuccess()){
						//构造查询条件进行本地日志查询
						InfTransLogQueryCondition conditionInfT = new InfTransLogQueryCondition();
						conditionInfT.setFundRasInsId(Long.valueOf(fundRasInsId));
						conditionInfT.setPrjId(Long.valueOf(prjId));
						conditionInfT.setAction(InterfaceConstants.Action.signAccount.key());
						List<InfTransLogDTO> dtos =  transLogApi.findTransLogs(conditionInfT);
						InfTransLogDTO transLog = null ;
						if (null != dtos && dtos.size() > 0) {
							transLog = dtos.get(0);
							String status = transLog.getStatus();
							if(InterfaceConstants.TransStatus.success.key().equals(status)){//短信验证成功
								BaseLogUtils.info(logger, "exchangeCardSave", "短信验证成功,prjid=" + prjId+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
								//调绑卡接口
								customerBankInfoDTO.setCustId(Long.valueOf(cstId));//客户id
								customerBankInfoDTO.setCustName(prjCstAccInfo.getCstNm());//客户名称
								customerBankInfoDTO.setBankName(bkCd);//银行代码
								customerBankInfoDTO.setBankCardNum(accNo);//银行账号
								customerBankInfoDTO.setPhone(mp);//预留手机号
								customerBankInfoDTO.setIdNo(certNo);//身份证号
								MessageDTO<String> bankCard = this.snApi.changeBankCard(Long.valueOf(fundRasInsId), Long.valueOf(prjId), customerBankInfoDTO);
								if("01".equals(bankCard.getCode())){//换绑卡成功bankCard.getCode()
									result.setSuccess(BaseConstant.IS_YESNO_YES);
									result.setInfo("换卡成功");
								}else{//换绑卡失败
									result.setSuccess(BaseConstant.IS_YESNO_NO);
									//result.setInfo(bankCard.getMessage());
									result.setInfo("换卡失败，请联系客户核实银行卡和预留手机号信息");
								}
							}else{//短信验证失败
								BaseLogUtils.info(logger, "getSignAccount", "短信验证失败,prjid=" + prjId+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
								result.setSuccess(BaseConstant.IS_YESNO_NO);
								result.setInfo("短信验证失败");
							}
						}else{
							BaseLogUtils.info(logger, "getSignAccount", "查询短信验证接口数据为空,prjid=" +prjId);
							result.setSuccess(BaseConstant.IS_YESNO_NO);
							result.setInfo("验证开户失败,查询短信验证接口数据为空");
						}
					}else{//短信验证失败
						BaseLogUtils.info(logger, "getSignAccount", "短信验证失败,prjid=" + prjId+",code="+messageDTO.getCode()+",message="+messageDTO.getMessage());
						result.setSuccess(BaseConstant.IS_YESNO_NO);
						result.setInfo("验证码有误，请核实");
					}
				}else if(chkRstCd.equals("0") || chkRstCd.equals("2")){//验证失败
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("四要素信息校验未通过，请核查四要素");
				}
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("四要素信息校验异常");
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("保存失败!");
			BaseLogUtils.error(logger, "save", "换卡保存失败 " + ex.getMessage());
			ex.printStackTrace();
		}
		return result;
	}
	/**
	 * 获取随机IP
	 *
	 * @return
	 */
	private static String getRandomIp() {
		// ip范围
		int[][] range = {{607649792, 608174079}, // 36.56.0.0-36.63.255.255
				{1038614528, 1039007743}, // 61.232.0.0-61.237.255.255
				{1783627776, 1784676351}, // 106.80.0.0-106.95.255.255
				{2035023872, 2035154943}, // 121.76.0.0-121.77.255.255
				{2078801920, 2079064063}, // 123.232.0.0-123.235.255.255
				{-1950089216, -1948778497}, // 139.196.0.0-139.215.255.255
				{-1425539072, -1425014785}, // 171.8.0.0-171.15.255.255
				{-1236271104, -1235419137}, // 182.80.0.0-182.92.255.255
				{-770113536, -768606209}, // 210.25.0.0-210.47.255.255
				{-569376768, -564133889}, // 222.16.0.0-222.95.255.255
		};
		Random rdint = new Random();
		int index = rdint.nextInt(10);
		String ip = num2ip(range[index][0] + new Random().nextInt(range[index][1] - range[index][0]));
		return ip;
	}

	/*
     * 将十进制转换成IP地址
     */
	private static String num2ip(int ip) {
		int[] b = new int[4];
		String x = "";
		b[0] = (int) ((ip >> 24) & 0xff);
		b[1] = (int) ((ip >> 16) & 0xff);
		b[2] = (int) ((ip >> 8) & 0xff);
		b[3] = (int) (ip & 0xff);
		x = Integer.toString(b[0]) + "." + Integer.toString(b[1]) + "." + Integer.toString(b[2]) + "." + Integer.toString(b[3]);

		return x;
	}
}
